import axios from './axiosExtend.js'
import { mediaUrl,shareUrl } from './api.config.js';
class getList{
    constructor(params, fn){
        this.params = params;
        this.callBack = fn; // 回调函数
        // social：代表social账号list  liveR: live视频list deleteSocial:删除social数据
        if(params.which && params.which == "social") {
            this.getSocialList();
        }
        if(params.which && params.which == "liveR") {
            this.getLiveRList();
        }
        if(params.which && params.which == "deleteSocial") {
            this.deleteSocial();
        }
    }
    getSocialList() {
        let _this = this;
		_getSocialList(_this.params).then(res => {
			if(res.data.errorCode == '0x0') {
				_this.callBack(res.data.result);
			}
		});
    }
    getLiveRList() {
        let _this = this;
        _getLiveRList().then(res => {
			if(res.data.errorCode == '0x0') {
				_this.callBack(res.data.result);
			}
		});
    }
    deleteSocial() {
        let _this = this;
        _deleteSocial(_this.params.id).then(res => {
			if(res.data.errorCode == '0x0') {
				_this.callBack("success");
			}else{
                _this.callBack(res.data.errorInfo);
            }
		});
    }
}

function _getSocialList(params) {
    let url = mediaUrl() + "account/listAccountInfo?nickName="+params.nickName+"&type="+params.type+"&pageNum="+params.pageNum+"&pageSize="+params.pageSize;
    return axios({
        url: url,
        method: 'get'
    });
}

function _deleteSocial(id) {
    let url = mediaUrl() + "account/accountInfo?id="+id;
    return axios({
        url: url,
        method: 'delete'
    });
}

function _getLiveRList() {
    let url = shareUrl() + "receiver/queryLiveRInfo";
    return axios({
        url: url,
        method: 'get'
    });
}

function _JumpToIframe(params, fn) {
    let flag = true;
    $("<iframe class='addOrEditIframe hide'" +
        "style='width: 100%;height: calc(100% - 80px);position: absolute;top: 80px;border:none;z-index: 10000;background-color: rgba(102, 102, 102, 0.65);'>" +
    "</iframe>").prependTo('body');
    $(".addOrEditIframe").attr("id", params.id);
    $(".addOrEditIframe").attr("operate-type", params.operateType);
    $(".addOrEditIframe").attr("src", params.url);
    if(params.operateType == 'edit'){
        $(".addOrEditIframe").attr("edit-data",JSON.stringify(params.row));
        $(".addOrEditIframe").attr("data-id", params.row.id);
    }
    $(".addOrEditIframe").load(function() {
        flag = false;
        $(".addOrEditIframe").removeClass("hide");
        fn(flag);
    });
}
export {
    getList,
    _getSocialList,
    _JumpToIframe
}
// 获取R数据